package com.ruoyi.initialdata.tool;

import com.ruoyi.initialdata.domain.SimpleIndex;
import com.ruoyi.initialdata.mapper.InitialDataTable1Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataToIndex {
    @Autowired
    private InitialDataTable1Mapper dataMapper;

    public void processData() {
        // 清空表 indicators
        dataMapper.deleteAllIndexes();

        // 查询去重后的data_index_name值
        List<String> distinctDataIndexNames = dataMapper.getDistinctDataIndexNames();
        // 遍历去重后的data_index_name值，插入表a
        int index = 1;
        for (String dataIndexName : distinctDataIndexNames) {
            SimpleIndex simpleIndex = new SimpleIndex();
            simpleIndex.setIndexId((long) index);
            simpleIndex.setIndexName(dataIndexName);

            // 插入表 indicators 的操作
            dataMapper.insertSimpleIndex(simpleIndex);
            System.out.println("id=" + index + ", name=" + dataIndexName);
            index++;
        }
    }
}
